import 'package:flutter/material.dart' hide SearchController;
import 'package:top_foundation/component/page_state/widgets/empty.dart';
import 'package:regular_assess/helper/utils/util.dart';

import '../index.dart';

/// hello
class SearchResultCell extends GetView<SearchController> {
  const SearchResultCell({
    Key? key,
    required this.md,
  }) : super(key: key);
  final dynamic md;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        controller.actionResultCell(md);
      },
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 12.r, vertical: 10.r),
        decoration: const BoxDecoration(
          color: Colors.white,
          border: Border(
            bottom: BorderSide(
              color: ColorsUtil.bg,
              width: 0.5,
            ),
          ),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              md.documentTitle ?? '',
              style: TextStyle(
                color: ColorsUtil.title,
                fontSize: 13.sp,
              ),
            ),
            SizedBox(
              height: 10.r,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Text(
                  md.publishTime?.split(' ').first ?? '',
                  style: TextStyle(
                    color: ColorsUtil.content,
                    fontSize: 12.sp,
                  ),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}

class SearchResultView extends GetView<SearchController> {
  const SearchResultView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var state = controller.state;
    return Column(
      children: [
        Container(
          padding: EdgeInsets.symmetric(horizontal: 12.r),
          height: 40.r,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                '搜索结果',
                style: TextStyle(
                  color: ColorsUtil.content,
                  fontSize: 13.sp,
                ),
              ),
            ],
          ),
        ),
        Expanded(
          child: isZeroList(state.results)
              ? const EmptyView(
                  title: '未搜索到相关结果',
                  url: 'assets/jsons/not_found.json',
                  isLottie: true,
                )
              : ListView(
                  children: state.results!
                      .map((e) => SearchResultCell(md: e))
                      .toList(),
                ),
        ),
      ],
    );
  }
}
